<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Insert title here</title>
    <link rel="stylesheet" href="__PUBLIC__/js/bootstrapvalidator/css/bootstrapValidator.min.css" />
	<link rel="stylesheet" href="__PUBLIC__/js/jquery-upload/css/jquery.fileupload.css" />
	<link rel="stylesheet" href="__PUBLIC__/js/jquery-upload/css/jquery.fileupload-ui.css" />
 	<script type="text/javascript" src="__PUBLIC__/js/jquery-upload/js/vendor/jquery.ui.widget.js"></script>
 	<script type="text/javascript" src="__PUBLIC__/js/jquery-upload/js/jquery.fileupload.js"></script>
 	<script type="text/javascript" src="__PUBLIC__/js/jquery-upload/js/jquery.fileupload-ui.js"></script>
 	<script type="text/javascript" src="__PUBLIC__/js/jquery-upload/js/jquery.iframe-transport.js"></script>
 	<script type="text/javascript" src="__PUBLIC__/js/jquery-upload/js/jquery.fileupload-process.js"></script>
 	<script type="text/javascript" src="__PUBLIC__/js/bootstrapvalidator/js/bootstrapValidator.min.js"></script>
	<link rel="stylesheet" href="__PUBLIC__/css/bootstrap-datetimepicker.css" />
</head>
<body>
	<div class="modal-dialog" role="document" style="width:800px;">
	    <div class="modal-content">
	        <div class="modal-header">
	            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	            <h4 class="modal-title" id="exampleModalLabel"><if condition="$id">修改预约会议<else/>预约会议</if></h4>
	        </div>
	        <form class="form-horizontal" style="padding-right: 17px;" id="meetingForm">
				<input type="hidden" name="token" value="{$formToken}">
	        	<input type="hidden"  name="id" value="{$id}"/>
				<input type="hidden" id="meetingRoomId" name="meetingRoomId" value="{$MeetingRoom.room.id}"/>
					<div class="panel-body">
						<div class="form-group">
							<label class="control-label col-sm-3">团队:</label>
							<div class="col-sm-4">
								<select class="form-control" name="team_id" id="team_id" onchange="showTeamSpaceIdOp()">
									<option  value="">--请选择--</option>
									<volist name="teams" id="item">
										<option  space_id="{$item.space_id}"<if condition="$MeetingRoom['team_id'] eq $item['id']">selected="selected"</if> value="{$item.id}">{$item.team_name}</option>
									</volist>

								</select>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-sm-3">会议室:</label>
							<div class="col-sm-4">
								<select class="form-control" id="meetingOrder" name="room_id">
									<option  value="">--请选择--</option>
								</select>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-sm-3">日期:</label>
							<div class='col-sm-4'  >
								<input id='datetimepicker6' type='text' value="{$MeetingRoom.start_time|default=$initDay|date='Y-m-d',###}" name="start_date" class="form-control" />
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-sm-3">起止时间:</label>
							<div class='col-sm-2'  >
								<input id='datetimepicker3' type='text' value="{$MeetingRoom.start_time|default=$initDay|date='Y-m-d H:i',###}" name="start_time" class="form-control" />
							</div>
							<div class='col-sm-2'  >
								<input id='datetimepicker4' type='text' value="{$MeetingRoom.end_time|default=$initDay|date='Y-m-d H:i',###}" name="end_time" class="form-control" />
							</div>
						</div>

						<div class="form-group">
							<label class="control-label col-sm-3">借用设备:</label>
							<div class="col-sm-2">
								<input type="checkbox" value="1"> 已归还
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-sm-3">主题:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" name="subject" value="{$MeetingRoom.subject}" placeholder="请输入主题">
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-sm-3">描述:</label>
							<div class="col-sm-6">
								<textarea class="form-control" rows="3" name="description">{$MeetingRoom.description}</textarea>
							</div>
						</div>
					</div>

	        </form>
	        <div class="modal-footer">
	            <button type="button" data-dismiss="modal" class="btn btn-default">取消</button>
	            <button type="button" id="save" class="btn btn-primary">保存</button>
	        </div>
	    </div>
	</div>
    
	<script type="text/javascript">
		var webRoot = "__ROOT__";
		var city = "{$space.city}";
        var county = "{$space.county}";
        var curDay = "{$curDay}"*1000;
        var initDay = "{$initDay}"*1000;
        var meeting_room_id = $('#meetingRoomId').val();
        $(function () {
            //$('#businessForm').validator();
            showTeamSpaceIdOp(meeting_room_id);
        })
        function showTeamSpaceIdOp() {
            var spaceId = $('#team_id').find('option:selected').attr("space_id");
            if(typeof(spaceId) == "undefined" || spaceId == "") {
                $("#meetingOrder").empty();
                var html = '<option value="">--请选择--</option>';
                $("#meetingOrder").html(html);
				return ;
			}
            $.ajax({
                url: "{:U('Admin/Space/Meeting/getMeetingByTeam')}",
                type: "post",
                data: {
                    'space_id': spaceId,
                },
                success: function (data) {
                    $("#meetingOrder").empty();
                    var html = '<option value="">--请选择--</option>';
                    if (data.length > 0) {
                        $.each(data, function (index, item) {
                            var strSelect = '';
                            if (item.id ==meeting_room_id) {
                                strSelect = ' selected';
                            }
                            html += '<option value="' + item.id + '"' + strSelect + '>' + item.name + '</option>';
                        });

                    }
                    $("#meetingOrder").html(html);
                }
            })
        }
        $('#datetimepicker6').datetimepicker({
            format: 'yyyy-mm-dd',
            language: 'ch',
            pickDate: true,
            pickTime: false,
            autoclose:true,
            minView:2,
			startDate: new Date(curDay),
			endDate: new Date(curDay+(30*24*60*60*1000))
            //pickerPosition:"bottom-left"
        }).on('changeDate', function(ev){
            if(ev.date){
				var curDate = ev.date.valueOf();
                $('#datetimepicker3').datetimepicker('setStartDate', new Date(curDate));
                $('#datetimepicker4').datetimepicker('setStartDate', new Date(curDate));
                $('#datetimepicker3').datetimepicker('setEndDate', new Date(curDate+((1*24*60*60-1)*1000)));
                $('#datetimepicker4').datetimepicker('setEndDate', new Date(curDate+((1*24*60*60-1)*1000)));
            }
        });
        $('#datetimepicker3').datetimepicker({
            format: 'hh:ii',
            language: 'ch',
            //pickDate: true,
            //pickTime: false,,
            autoclose: true,
//            minView: 2,
//            minuteStep:1,
            //startView:0,
            //pickerPosition:"bottom-left"
            startDate: new Date(initDay),
            endDate: new Date(initDay+((1*24*60*60-1)*1000)),
            startView: 1,
            minView: 0,
            maxView: 0,
            minuteStep: 15
        });
        $('#datetimepicker3').datetimepicker('show');
        $('#datetimepicker3').datetimepicker('hide');
        $('#datetimepicker4').datetimepicker({
            format: 'hh:ii',
            language: 'ch',
            //pickDate: true,
            //pickTime: false,,
            autoclose: true,
            startDate: new Date(initDay),
            endDate: new Date(initDay+((1*24*60*60-1)*1000)),
            startView: 1,
            minView: 0,
            maxView: 0,
            minuteStep: 15
            //pickerPosition:"bottom-left"
        });
        $('#datetimepicker4').datetimepicker('show');
        $('#datetimepicker4').datetimepicker('hide');
		$(function(){
			$("#save").bind("click",doSave);
		});
		
		var commitFlag = false;
		function doSave(){
            if(!validateForm()){
                commitFlag = false;
                return false;
            }
			$.ajax({
                url: "{:U('Admin/Space/Meeting/doSave')}",
                type: "post",
                dataType: "json",
                data: $("#meetingForm").serialize(),
                success: function (data) {
                    if(data.status){
                    	common.alert("提示",data.msg,function(){
                            common.reload();
                        });
                    }else{
                    	commitFlag = false;
                    	common.alert("提示",data.msg);
                    }
                }
            });
		}

        function validateForm(){
            $('#meetingForm').bootstrapValidator({
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    //invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    team_id: {
                        validators: {
                            notEmpty: {
                                message: '请选择预约团队'
                            }
                        }
                    },
                    room_id: {
                        validators: {
                            notEmpty: {
                                message: '请选择会议室'
                            }
                        }
                    },
                    start_date: {
                        validators: {
                            notEmpty: {
                                message: '预约日期不能为空'
                            }
                        }
                    },
                    start_time: {
                        validators: {
                            notEmpty: {
                                message: '起始时间不能为空'
                            }
                        }
                    },
                    end_time: {
                        validators: {
                            notEmpty: {
                                message: '截止时间不能为空'
                            }
                        }
                    },
                }
            });
            var data = $('#meetingForm').data('bootstrapValidator');
            if (data) {
                data.validate();
                if (!data.isValid()) {
                    return false;
                }
            }
            return true;
        }

	</script>
</body>
</html>